function [value,isterminal,direction] = events1(t,z)

% Detect H = 0.


H=z(2);

value = H;

isterminal = 1;   % Stop the integration
direction = -1;   % it's initially positive and decreasing to zero